package com.ews.onlineexchange.rest;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.faces.bean.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.ews.onlineexchange.service.assess.AssessRecordService;

@Path( value = "/assessRecords" )
@RequestScoped
public class AssessRecordRest {
	
	@Inject
	AssessRecordService assessRecordService;
	
	@GET    
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
	@Path( value = "/archive/{id}" )
	public Response archive( @PathParam( "id" ) String id ) throws UnsupportedEncodingException {
		File zipFile = assessRecordService.archive( id );
		
		ResponseBuilder response = Response.ok( zipFile );
		response.header("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode( zipFile.getName(), "UTF-8" ) );
		return response.build();
	}
	
	
	
}
